package com.okaixz.manager.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.okaixz.common.annotation.Log;
import com.okaixz.common.core.controller.BaseController;
import com.okaixz.common.core.domain.AjaxResult;
import com.okaixz.common.enums.BusinessType;
import com.okaixz.manager.domain.Tab;
import com.okaixz.manager.service.ITabService;
import com.okaixz.common.utils.poi.ExcelUtil;
import com.okaixz.common.core.page.TableDataInfo;

/**
 *  二级菜单管理Controller
 * 
 * @author ruoyi
 * @date 2024-08-17
 */
@RestController
@RequestMapping("/manager/tab")
public class TabController extends BaseController
{
    @Autowired
    private ITabService tabService;

    /**
     * 查询 二级菜单管理列表
     */
    @PreAuthorize("@ss.hasPermi('manager:tab:list')")
    @GetMapping("/list")
    public TableDataInfo list(Tab tab)
    {
        startPage();
        List<Tab> list = tabService.selectTabList(tab);
        return getDataTable(list);
    }

    /**
     * 导出 二级菜单管理列表
     */
    @PreAuthorize("@ss.hasPermi('manager:tab:export')")
    @Log(title = " 二级菜单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Tab tab)
    {
        List<Tab> list = tabService.selectTabList(tab);
        ExcelUtil<Tab> util = new ExcelUtil<Tab>(Tab.class);
        util.exportExcel(response, list, " 二级菜单管理数据");
    }

    /**
     * 获取 二级菜单管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manager:tab:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tabService.selectTabById(id));
    }

    /**
     * 新增 二级菜单管理
     */
    @PreAuthorize("@ss.hasPermi('manager:tab:add')")
    @Log(title = " 二级菜单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Tab tab)
    {
        return toAjax(tabService.insertTab(tab));
    }

    /**
     * 修改 二级菜单管理
     */
    @PreAuthorize("@ss.hasPermi('manager:tab:edit')")
    @Log(title = " 二级菜单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Tab tab)
    {
        return toAjax(tabService.updateTab(tab));
    }

    /**
     * 删除 二级菜单管理
     */
    @PreAuthorize("@ss.hasPermi('manager:tab:remove')")
    @Log(title = " 二级菜单管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tabService.deleteTabByIds(ids));
    }
}
